(function($){
	var defaults = {
		_interval : 5000,
		_dist : 50,
		accorClick : function(){},
		company		: "靸侅儊鞚橃瀽鞙�",
		author 		: "kissyweb@gmail.com"
	};

	$.fn.rollFx = function(options){
		var I_F 			= {};
		var _class 		= this.attr("id");
		var _timer;
		var _length;
		var _currentIndex = 0;

		var init = function(){
			I_F.set = $.extend({}, defaults, options);
			loadedFx();
			bulletClick();
		};
		var loadedFx = function(){
			_length = $("#"+_class+" .content ul").length;
			_timer = setInterval( function(){updateCounter()}, I_F.set._interval);
		};

		var bulletClick = function(){
			$("#"+_class+" .bullet li").click(function($index){
				clearInterval(_timer);
				_currentIndex = $(this).index();
				$("#"+_class+" .content ul li").each(function(_i){
					$(this).stop();
					$(this).css({"opacity":1});
					$(this).removeAttr("style");
				});

				$("#"+_class+" .content ul").each(function(_i){
					$(this).css("display","none");
				});

				 $("#"+_class+" .content ul:eq("+_currentIndex+")").css("display","block");
				 $(this).addClass('on').siblings().removeClass();
				 loadedFx();
				 animateShow();
			});
		}


		var updateCounter = function() {
			// clearInterval(_timer);
			animateHide();
			_currentIndex++;
			_currentIndex = _currentIndex%_length;
			// console.log( _currentIndex, "_currentIndex" )
		};

		var animateHide  = function(){
			var _current = $("#"+_class+" .content ul:eq("+_currentIndex+") li");
			var _length = _current.length;

			_current.each(function($index){
				$(this).css({"borderSpacing":0, "opacity":1});
				$(this).delay($index*100).animate({  borderSpacing: 1 }, {
					step: function(now,fx) {
						_now = -now*I_F.set._dist;
						$(this).css({'transform':'matrix(1,0,0,1,0,'+_now+')',
									'-webkit-transform':'matrix(1,0,0,1,0,'+_now+')',
									'-moz-transform':'matrix(1,0,0,1,0,'+_now+')',
									'opacity':1-now
						});
					},duration:500,
					// easing :'easeOutCubic',
					complete: function(){
						if(_length <= $index+1){
							$(this).parent().css({"display":"none"});
							animateShow();

						}
					}
				})
			});
		};
		var animateShow  = function(){
			bulletSelect(_currentIndex)
			var _current = $("#"+_class+" .content ul:eq("+_currentIndex+") li");
			var _length = _current.length;
			_current.parent().css({"display":"block"});
			_current.each(function($index){
				$(this).css({"borderSpacing":0, "opacity":0,
									'transform':'matrix(1,0,0,1,0,'+I_F.set._dist+')',
									'-webkit-transform':'matrix(1,0,0,1,0,'+I_F.set._dist+')',
									'-moz-transform':'matrix(1,0,0,1,0,'+I_F.set._dist+')'
				});
				$(this).delay($index*100).animate({  borderSpacing: 1 }, {
					step: function(now,fx) {
						_now = I_F.set._dist - now*I_F.set._dist;
						$(this).css({'transform':'matrix(1,0,0,1,0,'+_now+')',
									'-webkit-transform':'matrix(1,0,0,1,0,'+_now+')',
									'-moz-transform':'matrix(1,0,0,1,0,'+_now+')',
									'opacity':now
						});
					},duration:500,
					// easing :'easeInCubic',
					complete: function(){
						if(_length <= $index+1){
							// clearInterval(_timer);

						}
					}
				})
			});
		};

		var bulletSelect = function($i){
			$("#"+_class+" .bullet li:eq("+$i+")").addClass('on').siblings().removeClass();
		}

		//////////
		init();
		return this;
	};
})(jQuery);